// ============================== 导入依赖 ============================== //

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  async remoteOne({ state: { API, MAP, one, param: { beginTime, endTime } } }) {
    const TIP = API.transTip(MAP.tipOne)
    const obj = await API.getOne({ monitPointSiteId: one.monitorPointSiteId, beginTime, endTime }, TIP)
    return transOne(obj, one)
  },
}

// ============================== 转换方法 ============================== //

const transOne = ({ content }, one) => {
  Object.assign(one, { xData: [], dataList: [[], [], []] })

  Object.keys(content).forEach((key) => {
    const data = content[key]
    one.xData.push(key)
    one.dataList[0].push(data.peak)
    one.dataList[1].push(data.valley)
    one.dataList[2].push(data.flat)
  })

  return one
}
